<template>
  <el-card>
    <el-tabs v-model="activeName">
      <el-tab-pane label="登录账户设置" name="loginInfo">
        <el-form
          ref="userForm"
          :rules="rules"
          :model="userInfo"
          label-width="80px"
          style="width: 350px; margin: 50px auto"
        >
          <el-form-item prop="username" label="姓名：">
            <el-input v-model="userInfo.username"></el-input>
          </el-form-item>
          <el-form-item prop="password" label="密码：">
            <el-input v-model="userInfo.password" type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="updataClick">更新</el-button>
            <el-button @click="$router.back()">取消</el-button>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="个人详情" name="userInfo">
        <user-info />
      </el-tab-pane>
      <el-tab-pane label="岗位信息" name="jobInfo">
        <job-info />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script>
import { getUsername } from "@/api/user.js"; //基本员工信息
import { updataUserinfo } from "@/api/employees.js"; //更新信息
import userInfo from "./components/userinfo.vue"; //导入子组件
import jobInfo from "./components/job-info.vue"; //导入子组件
export default {
  components: {
    userInfo,
    jobInfo,
  },
  data() {
    return {
      activeName: "loginInfo",
      userInfo: {},
      rules: {
        username: [
          { required: true, message: "姓名不能为空!", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不能为空!", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getLoading();
  },
  methods: {
    //   获取基本资料
    async getLoading() {
      let res = await getUsername(this.$route.query.id);
      //   console.log(res);
      this.userInfo = res.data;
    },
    // 确定更新数据点击事件
    updataClick() {
      // 表单验证
      this.$refs.userForm.validate(async (isok) => {
        if (isok) {
          await updataUserinfo(this.userInfo);
          this.$message.success("更新成功!");
          this.$router.back(); //返回上一页
        }
      });
    },
  },
};
</script>

<style>
</style>